// ignore_for_file: deprecated_member_use

import 'package:dmz/base/widget/back_image_widget.dart';
import 'package:dmz/business/login/widgets/login_widgets.dart';
import 'package:dmz/routers/routers.dart';
import 'package:dmz/user/user_defurl.dart';
import 'package:dmz/utils/customize_loding.dart';
import 'package:dmz/utils/preference_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../tools/verify/face_id_manger.dart';
import '../widgets/logo_widget.dart';

class LoginFirstPage extends StatefulWidget {
  const LoginFirstPage({super.key});

  @override
  State<LoginFirstPage> createState() => _LoginFirstPageState();
}

class _LoginFirstPageState extends State<LoginFirstPage> {
  @override
  void initState() {
    super.initState();
    debugPrint('首页加载');
    Future.delayed(const Duration(milliseconds: 1000), () {
      if (!PreferenceUtils().getBool('showAgree')) {
        EMILoding.showInteractivePopUpBox(context, popUpsturnNext);
      } else {
        if (PreferenceUtils().getString('token').isNotEmpty) {
          EMIFaceIDManger().authenticate().then((scuess) {
            if (scuess) Get.offAllNamed(RouteGet.main);
          });
        }
      }
    });
  }

  @override
  void didUpdateWidget(covariant LoginFirstPage oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  Widget build(BuildContext context) {
    return BackImageWidget(
        isLogin: false,
        child: Column(children: [logoWidget(context), btns(context)]));
  }

  logoWidget(context) {
    return const LogotWidget()
        .marginOnly(top: MediaQuery.of(context).size.height / 4);
  }

  Widget btns(BuildContext context) {
    return Column(children: [
      LoginWidgets.loginOtherBtn(context, () => Get.toNamed(RouteGet.login)),
      LoginWidgets.loginBtn(() {},
          title: '虚拟体验'.tr,
          margin: EdgeInsets.only(left: 40.sp, right: 40.sp, top: 32.sp))
    ]).marginOnly(top: 400.sp);
  }

  ///窗口操作
  popUpsturnNext(int type) {
    switch (type) {
      case 0: //协议
        EMIBUserManger().launchURL(type);
        break;
      case 1: //隐私
        EMIBUserManger().launchURL(type);
        break;
      case 2: //不同意
        SystemNavigator.pop();
        break;
      case 3: //同意
        PreferenceUtils().putBool('showAgree', true);
        break;
      default:
    }
  }

  ///人脸登录
}
